{extends file="../home.html"}
{block name="title"}{$head_title}{/block}

{block name="css"}
<link href="__PUBLIC__/Css/front/css/publish_post.css?version={$version}" type="text/css" rel="stylesheet">
<style>
    .confirm_box{
    background: rgba(0,0,0,.4);
    font-size: 15px!important;
    z-index: 9999;
    text-align: center;
    overflow: hidden;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}
.confirm_box>div {
    overflow: hidden;
    position: absolute;
    left: 13.5%;
    top: 50%;
    width: 73%;
    background: #fff;
    border-radius: 10px;
    text-align: center;
    vertical-align: middle;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
}

.confirm_box>div>h1 {
    font-size: 15px!important;
    font-style: normal;
    padding: 15px 10px 10px;
    color: #333;
}
.confirm_box> div > a {
    font-size: 16px !important;
    display: block;
    line-height: 40px;
    color: #007AFF;
    text-decoration: none;
    border-top: 1px solid #DBDCDC;
}
.confirm_box i{
    font-style: normal;
    float: left;
    width: 50%;
}
.confirm_box i:first-child {
    margin-right: -1px;
    border-right: 1px solid #DBDCDC;
}
</style>
{/block}
{block name="content"}

	
	<div class="com_header">
		<a href="javascript:;" class="go_back"><i class="icon_back"></i></a>{$head_title}
	</div>
    
	<form>
		<div class="reply" style="margin-top: 2.2rem">
			{include file="./common_post.html"}
			{if $opt == 'praise'}
				{include file="./praise_hide.html"}
			{/if}
		</div>
			{if $opt == 'praise'}
				{include file="./praise_price.html"}
			{elseif $opt == 'reward'}
				{include file="./reward_price.html"}
			{elseif $opt == 'crowdfunding'}
				{include file="./crowdfunding_price.html"}
			{/if}
	</form>
	
	{if $opt == 'reward'}
		<div class="tips">
			1、请在{$reward_days}天内采纳一个“最佳答案”<br>
			2、如果{$reward_days}天内无人回答，您可以申请退款<br>
			3、所有围观用户的消耗将有{$look_rate}%分配给您，另{100 - $look_rate}%%计入到赏金总额。<br>
		</div>
	{/if}

	<div class="fixed_bot" id="post"> 
		发表
	</div>

    {if $opt == 'reward'}
    <!-- 选择我关注的人 -->
    <div class="my_follow" style="display: none;">
        <div class="com_header">
            <span class="cancel">取消</span></a>我关注的人<span class="ensure">确定</span>
        </div>
        <h5 style="margin-top: 2.2rem;">我关注了{count($followed_users)}人</h5>
        <ul class="user_list">
            {foreach from=$followed_users item=v}
            <li data-user_id="{$v.user_id}">
                <img src="{$v.headimgurl}" alt="">
                <span class="nickname">{$v.nickname}</span>
                <i class="icon_nochoose"></i>
            </li>
            {/foreach}
        </ul>
    </div>
    {/if}
    
    <p style="padding:0 .6rem;font-size: .7rem;line-height: 1rem;color: #909090;">发帖后你将不能对帖子再进行编辑！</p>

    <!-- 提交审核 -->
    {if $opt == 'crowdfunding'}
    <div class="submit_review" style="display: none;">
         <div class="com_header">
            <a href="javascript:;" class="go_back"><i class="icon_back"></i></a>提交审核
        </div>
        <div class="succ">
            <img src="/Public/Images/img/icon_chou_shenhe@3x.png" alt="">
            <h4>提交成功</h4>
            <p>已提交后台审核，审核成功会已消息的形式通知哦</p>
        </div>
    </div>
    {/if}

    
    <!-- 删除提示 -->
    <div class="confirm_box" style="display: none;">
        <div>
            <h1>发帖后无法删除或修改，确认发帖吗？</h1>
            <!-- <p>提示内容</p> -->
            <a><i id="confirmOk">确定</i><i id="confirmCancel">取消</i></a>
        </div>
    </div>
    
{/block}
{block name="js"}


<script type="text/javascript">
	var uptoken = $('#uptoken').val()
var image_domain = $('#image_domain').val();
var channel_id = parseInt('{$channel_id}');
var posting = false;

{if $is_ht}
var post_id = parseInt('{$post_id}');
{/if}
// if(!is_ios()){
//     $("input[name=file]").attr({
//         'capture':'camera',
//         'accept':'image/*'
//     });
// }
</script>


<!-- 开发调试-->
<!-- <script type="text/javascript" src="__JS__/plupload_js/moxie.js"></script> -->
<!-- 下面三个plupload文件选择其一 -->
<!-- 基于jq版本的Plupload插件封装 -->
<!-- <script type="text/javascript" src="__JS__/plupload_js/jquery.plupload.queue/jquery.plupload.queue.js"></script> -->
<!-- 基于js版本 -->
<!-- <script type="text/javascript" src="__JS__/plupload_js/plupload.dev.js"></script> -->
<!-- <script type="text/javascript" src="__JS__/plupload_js/plupload.min.js"></script> -->

<!-- 生产环境 -->
<script type="text/javascript" src="__JS__/plupload_js/plupload.full.min.js"></script>

 <!-- qiniu.min.js（生产环境）或 qiniu.js（开发调试） -->
<script type="text/javascript" src="__JS__/qiniu.js"></script>
<!-- <script type="text/javascript" src="__JS__/qiniu.min.js"></script> -->

{if $opt == 'normal'}
<script src="/Public/Js/front/js/post_tiezi.js"></script>
{elseif $opt == 'praise'}
    {if $is_ht}
    <script src="/Public/Js/front/js/zs_lz_ht.js"></script>
    {else}
    <script src="/Public/Js/front/js/post_zs.js"></script>
    {/if}
{elseif $opt == 'reward'}
<script src="/Public/Js/front/js/post_xs.js"></script>
{elseif $opt == 'crowdfunding'}
<script src="/Public/Js/front/js/post_zc.js"></script>
{/if}

<script>

{literal}


//输入框自适应
$("#content").each(function(){
    this.style.height = this.scrollHeight + "px";
});
$("#content").on({
    input:function(){
        var _this = this;
        this.style.height = this.scrollHeight + "px";
    },
    propertychange:function(){
        this.style.height = this.scrollHeight + "px";
    }
});
$(document).on("input propertychange", "#content", function (e) {
   var target = e.target;
   // 保存初始高度，之后需要重新设置一下初始高度，避免只能增高不能减低。           
    var dh = $(target).attr('defaultHeight') || 0;
    if (!dh) {
        dh = target.clientHeight;
        $(target).attr('defaultHeight', dh);
    }
    target.style.height = dh +'px';
    var clientHeight = target.clientHeight;
    var scrollHeight = target.scrollHeight;
    if (clientHeight !== scrollHeight) { target.style.height = scrollHeight + 10 + "px";
    }
});
$("#hide_content").each(function(){
    this.style.height = this.scrollHeight + "px";
});
$("#hide_content").on({
    input:function(){
        var _this = this;
        this.style.height = this.scrollHeight + "px";
    },
    propertychange:function(){
        this.style.height = this.scrollHeight + "px";
    }
});
$(document).on("input propertychange", "#hide_content", function (e) {
   var target = e.target;
   // 保存初始高度，之后需要重新设置一下初始高度，避免只能增高不能减低。           
    var dh = $(target).attr('defaultHeight') || 0;
    if (!dh) {
        dh = target.clientHeight;
        $(target).attr('defaultHeight', dh);
    }
    target.style.height = dh +'px';
    var clientHeight = target.clientHeight;
    var scrollHeight = target.scrollHeight;
    if (clientHeight !== scrollHeight) { target.style.height = scrollHeight + 10 + "px";
    }
});

//七牛多图上传
 var uploader = new plupload.Uploader({
        runtimes : 'html5',//上传模式
        browse_button : 'upload_btn', //触发文件选择对话框的按钮，为那个元素id
        url : 'https://up.qbox.me/', //服务器端的上传页面地址
        filters : {
            // 设置大小
            max_file_size : '10mb',
            // 允许上传的类型
           mime_types: [
             //{title : "Image files", extensions : "png,jpeg,gif,bmp,jpg"}
           ]
        },
        multipart: true,
        //设置post传给七牛的token
        multipart_params: {
            'token': uptoken, 
        },
        //修改post字段为七牛的file
        file_data_name: 'file',
        init: {
            PostInit: function() {
                console.log("upload init");
                if(!is_ios()){
                    $("input[type=file]").attr({
                        'capture':'camera',
                        'accept':'image/*'
                    });
                }
            },
            FilesAdded: function(up, files) {
                plupload.each(files, function(file) {
                    // 文件添加进队列后,处理相关的事情
                    //console.log(file);
                    
                });
                //选择文件后直接上传， 或可改成点击按钮上传
                uploader.start();
            },
            UploadProgress: function(up, file) {

            },
            FileUploaded: function(up, file, info) {
                console.log(info);
                var res =JSON.parse(info.response);
                var sourceLink = image_domain + res.key; //获取上传成功后的文件的Url  
                var  html = '<li><img src="'+sourceLink+'?imageView2/1/w/200/h/200/imageslim" alt="" data-link="'+sourceLink+'"><span class="del_img" onclick="del_img(this)"></span></li>';
                var container = $('#img_list1');
                container.append(html);
                var imgs = $('#upload_btn').parent().siblings('.img_url').val();
                imgs += ','+sourceLink;
                $('#upload_btn').parent().siblings('.img_url').val(imgs);
            },
            UploadComplete: function(up, files) {
                //队列文件处理完毕后,处理相关的事情
                console.log('上传成功');
            },
            Error: function(up, err) {
                //上传出错时,处理相关的事情
            }
        } 
    });  

    uploader.init();

  // 七牛官方demo
  // var uploader = Qiniu.uploader({
  //   runtimes: 'html5',
  //   browse_button: 'upload_btn',
  //   max_file_size: '1000mb',
  //   chunk_size: '4mb',
  //   multi_selection: !(moxie.core.utils.Env.OS.toLowerCase() === "ios"),
  //   domain: image_domain,
  //   get_new_uptoken: false,
  //   uptoken:uptoken,
  //   auto_start: true,
  //   multi_selection: 'select_multiple',
  //   log_level: 5,
  //   init: {
  //     'BeforeChunkUpload': function(up, file) {

  //     },
  //     'FilesAdded': function(up, files) {
  //       plupload.each(files, function(file) {
  //           console.log('文件名'+file.name)
  //       });
  //     },
  //     'BeforeUpload': function(up, file) {

  //     },
  //     'UploadProgress': function(up, file) {


  //     },
  //     'UploadComplete': function() {

  //     },
  //     'FileUploaded': function(up, file, info) {

  //       console.log("上传图片信息", info);
  //       var res =JSON.parse(info);
  //       var sourceLink = image_domain + res.key; //获取上传成功后的文件的Url  
  //       console.log(sourceLink);
  //       var  html = '<li><img src="'+sourceLink+'?imageView2/1/w/200/h/200/imageslim" alt="" data-link="'+sourceLink+'"><span class="del_img" onclick="del_img(this)"></span></li>';
  //       var container = $('#img_list1');
  //       var imgs = $('#upload_btn').parent().siblings('.img_url').val();
  //       imgs += ','+sourceLink;
  //       $('#upload_btn').parent().siblings('.img_url').val(imgs);
  //       container.append(html);
  //     },
  //     'Error': function(up, err, errTip) {

  //       }
  //   }
  // });


    if(!is_ios()){
        $("input[type=file]").attr({
            'capture':'camera',
            'accept':'image/*'
        });
    }

    function del_img(obj){
    	var obj_init = $(obj);
        obj_init.parent().remove();
        var imgs = '';
        $('#img_list1 li').each(function(){
        	imgs += ','+$(this).find('img').data('link');
        })
        $('#img_url').val(imgs)
    }




$(function(){

    // 选择金额
    $('.money').on('click',function(){
    	$(this).addClass('active').siblings().removeClass('active')
    })
    $('.select_friend').on('click',function(){
        $('.my_follow').show();
    })
   
})

// $('.fixed_bot').on('click',function(){
// 	var title = $('#title').val();
// 	if(!title){
// 		alert('请输入标题');
// 		return 
// 	}
// })

	
// function upload_image(obj){
// 	var token = $("#uptoken").val();
// 	var image_domain = $("#image_domain").val();

// 	if ($(obj)[0].files.length > 0 && token != "") {
//         // uploader();
//     } else {
//         layer.open({
//         	title:false,
//         	content:"请选择图片",
//         	btn:["确定"]
//         });
//     }
// }


// $("#upload_btn").on("click", function(){
// 	return $("#uploader").click();
// });



{/literal}
</script>

{/block}